/*
 *  HDU: 1506
 */

/*-------- Includes --------*/
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/
typedef long long ll;

/*-------- Global Variables --------*/
int n;
ll  h[100002];
int L[100002];
int R[100002];
int stack[100002];
int top;

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    while (cin >> n && n) {
        for (int i = 0; i < n; i++) cin >> h[i];

        top      = 1;
        stack[0] = -1;
        stack[1] = 0;
        L[0]     = -1;
        for (int i = 1; i < n; i++) {
            while (top > 0 && h[stack[top]] >= h[i]) top--;

            L[i]         = stack[top];
            stack[++top] = i;
        }

        top      = 1;
        stack[0] = n;
        stack[1] = n - 1;
        R[n - 1] = n;
        for (int i = n - 2; i >= 0; i--) {
            while (top > 0 && h[stack[top]] >= h[i]) top--;

            R[i]         = stack[top];
            stack[++top] = i;
        }

        ll maxi = -1;
        for (int i = 0; i < n; i++) {
            maxi = max(maxi, (R[i] - L[i] - 1) * h[i]);
        }

        cout << maxi << endl;
    }

    return 0;
}

/*-------- Functions --------*/

